#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <mpi.h>

struct {
    int val;
    int   rank;
} in, out;

int main(int argc, char *argv[])
{
    int size, rank;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    srand(rank);
    in.val = rand()%101;  //产生0-100的随机数
    in.rank = rank;

    MPI_Reduce(&in, &out, 1, MPI_2INT, MPI_MAXLOC, 0,MPI_COMM_WORLD);
    if (rank == 0) {
        printf("MAX = ");
        printf("%d, rank = %d",out.val,out.rank);
        putchar('\n');
    }
    MPI_Finalize();
    return 0;
}
